/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ceair.flight.refund.service.cronjob.autocheck.impl;

import com.ceair.flight.refund.dto.appmoblie.RefundApplyDto;
import com.ceair.flight.refund.location.dt.enums.RefundReasonEnum;
import com.ceair.flight.refund.service.cronjob.validator.IValidator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 本地数据检查申请单是否可自动一审
 *
 * @author youguilin
 */
@Service("voluntaryChecker")
@Order(value = 100)
public class VoluntaryChecker extends BaseValidatorChecker {

    private static final Logger LOG = LoggerFactory.getLogger(VoluntaryChecker.class);
    @Resource(name = "basicVoluntaryValidator")
    private IValidator basicVoluntaryValidator;

    public VoluntaryChecker() {
        super("voluntaryChecker");
    }

    @Override
    public boolean autoCheck(final RefundApplyDto refundApply) {
        final RefundReasonEnum reasonEnum = super.getRefundReason(refundApply);
        if (reasonEnum == null) {
            LOG.warn("Unknow refund apply claim type, stop auto auditting");
            return false;
        } else {
            LOG.debug("Refund apply is voluntary: {}", reasonEnum.isVoluntary());
            if (reasonEnum.isVoluntary()) {
                return super.validate(refundApply);
            }
        }
        return super.goNextOrReturn(refundApply);
    }

    @Override
    IValidator getValidator(RefundApplyDto refundApply) {
        return basicVoluntaryValidator;
    }

}
